package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SkuInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SkuController
 * @Description 此类描述:
 * @Author dangchen
 * @DateTime 2022-11-01 20:03
 * @Version 1.0
 */
@RestController
@RequestMapping("admin/product")
public class SkuController {

    @Autowired
    SkuInfoService skuInfoService;

    /**
     * 添加sku
     * @param skuInfoVo
     * @return
     */
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok();
    }

    /**
     * 获取sku分页列表
     * @param pg
     * @param lm
     * @return
     */
    @GetMapping("list/{page}/{limit}")
    public Result getList(@PathVariable("page") Long pg,
                          @PathVariable("limit") Long lm){
        Page<SkuInfo> page = new Page<>(pg,lm);
        Page<SkuInfo> result = skuInfoService.page(page);
        return Result.ok(result);
    }
}
